
package fileby.ctrl.breadcrumbs;

import fileby.core.SourceType;
import fileby.model.ISourceHandler;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;

/**
 *
 * @author Jacob
 */
public class BreadCrumbListener extends MouseAdapter {

    private ISourceHandler sourceHandler;

    public BreadCrumbListener(ISourceHandler sourceHandler) {
        this.sourceHandler = sourceHandler;
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        mouseClicked(e);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        JPanel p = (JPanel)e.getComponent();
        p.grabFocus();
        String sourceType = p.getName().substring(0, p.getName().indexOf(";"));
        String absolutePath = p.getName().substring(p.getName().indexOf(";")+1);
        sourceHandler.replaceCurrentSource(SourceType.valueOf(sourceType), absolutePath);
    }

}
